package com.zhaimen.module.product.dal.mysql.homelink;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhaimen.framework.common.enums.CommonStatusEnum;
import com.zhaimen.framework.common.pojo.PageResult;
import com.zhaimen.framework.mybatis.core.mapper.BaseMapperX;
import com.zhaimen.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zhaimen.module.product.controller.admin.homelink.vo.HomeLinkPageReqVO;
import com.zhaimen.module.product.dal.dataobject.homelink.HomeLinkDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface HomeLinkMapper extends BaseMapperX<HomeLinkDO> {
    default HomeLinkDO selectByName(String name) {
        HomeLinkDO homeLinkDO = selectOne(HomeLinkDO::getName, name);
        return homeLinkDO;
    }

    default PageResult<HomeLinkDO> selectPage(HomeLinkPageReqVO reqVO) {
        PageResult<HomeLinkDO> pageResult = selectPage(reqVO, new LambdaQueryWrapperX<HomeLinkDO>()
                .likeIfPresent(HomeLinkDO::getName, reqVO.getName())
                .eqIfPresent(HomeLinkDO::getCommonStatus, reqVO.getCommonStatus())
                .eqIfPresent(HomeLinkDO::getLinkType, reqVO.getLinkType())
        );
        return pageResult;
    }

    default List<HomeLinkDO> selectByCommonStatus(Integer status){
        List<HomeLinkDO> homeLinkDOS = selectList(HomeLinkDO::getCommonStatus, CommonStatusEnum.ENABLE.getStatus());
        return homeLinkDOS;
    }
}
